<template>
  <div>
    <div>
      <ele-form-search
        v-model="formData"
        :formConfig="formConfig"
        @handleSearch="handleSearchPageOne"
        @handleReset="handleReset"
        ref="eleFormSearch"
      ></ele-form-search>

      <div style="margin-top: 10px;margin-bottom: 10px">
        <el-button type="primary" icon="el-icon-plus" @click="add">新增集采需求</el-button>
        <el-button type="primary" icon="el-icon-plus" @click="spIn">特殊入库</el-button>
<!--        <el-button type="primary" icon="el-icon-search" @click="show">查看需求</el-button>-->
      </div>
      <div>
        <el-table
          border
          :data="tableData"
          style="width: 100%"
          v-tableMaxHeight
          :pagination="true"
          :row-class-name="tableRowClassName"
          :height="selfMaxHeight">
          <el-table-column type="index" label="序号" align="center"></el-table-column>
          <el-table-column type="expand" align="center">
            <template slot-scope="scope">
              <el-table
                border
                :data="scope.row.children"
                style="width: 98%;margin: auto">
                <el-table-column type="index" label="序号" align="center"></el-table-column>
                <el-table-column label="仓库名" prop="warehouseName" align="center"  :formatter="formatter"></el-table-column>
                <el-table-column label="物料名" prop="itemName" align="center"></el-table-column>
                <el-table-column label="品牌" prop="itemBrand" align="center"></el-table-column>
                <el-table-column label="规格" prop="itemUnit" align="center"></el-table-column>
                <el-table-column min-width="180" label="供应商" prop="itemSupName" align="center"></el-table-column>
                <el-table-column min-width="160" label="VIN" prop="itemVin" align="center"></el-table-column>
                <el-table-column label="物料总量" width="80" prop="itemNum" align="center"></el-table-column>
                <el-table-column label="物料单位" width="80" prop="materialUnit" align="center"></el-table-column>
                <el-table-column label="包装数" width="80" prop="itemPackCount" align="center"></el-table-column>
                <el-table-column label="包装单位" width="80" prop="itemPackUnit" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="120">
                  <template slot-scope="scope2">
                    <el-button
                      size="mini"
                      type="primary "
                      @click="handleOutSpecial(scope2.row)">特殊出库</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column label="物料名称" prop="itemNameShow" align="center"></el-table-column>
<!--          <el-table-column label="物料编号" prop="itemCode" align="center"></el-table-column>-->
          <el-table-column label="数量" prop="itemNum" align="center"></el-table-column>
          <el-table-column label="单位" prop="materialUnit" align="center"></el-table-column>
          <el-table-column label="安全库存" prop="materialSafetyStock" align="center"></el-table-column>
        </el-table>
      </div>
      <div >
        <el-pagination
          class="lb-table-pagination"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 30, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          background
          :style="{ 'margin-top': '15px', 'text-align': 'right' }">
        </el-pagination>
      </div>

<!--      <ele-page-->
<!--        v-loading="loading"-->
<!--        :formConfig="formConfig"-->
<!--        ref="eleTable"-->
<!--        :operateList="operateList"-->
<!--        @handleOperateEvent="handleOperateEvent"-->
<!--        :column="column"-->
<!--        :getList="mesKtStockInfoPage"-->
<!--        uniqueId="equipmentLedgerListTable"-->
<!--        :customRowClick="rowClick"-->
<!--      >-->
<!--      </ele-page>-->
<!--      <ele-dialog-table-->
<!--        ref="dialogTable"-->
<!--        title="详情"-->
<!--        :visible.sync="detailVisible"-->
<!--        :getList="mesKtStockInfoDetailPage"-->
<!--        :column="columnDetail"-->
<!--        :formConfig="{}"-->
<!--        :otherParam="otherParam"-->
<!--        :hasFooter="false"-->
<!--      >-->
<!--      </ele-dialog-table>-->

      <ele-form-drawer
        :isLoading="isLoading"
        v-model="formDataDialog"
        v-bind="formDescDialog"
        :request-fn="handleSubmit"
        :visible.sync="visible"
        :title="title"
      >
        <template v-slot:materialName>
          <el-input v-model="formDataDialog.materialName"
                    readonly
                    placeholder='请选择物料'>
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="mixinDialogVisibleJc = true"></el-button>
          </el-input>
        </template>
        <template v-slot:materialBrand>
          <el-select
            v-model="formDataDialog.materialBrand"
            filterable
            style="width:100%"
            placeholder="请选择品牌"
            class="accredit-select"
            @change="getMaterialUnit(formDataDialog)"
          >
            <el-option
              v-for="item in brandList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </template>
        <template v-slot:materialUnit>
          <el-select
            v-model="formDataDialog.materialUnit"
            filterable
            @change="materialUnitChange"
            style="width:100%"
            placeholder="请选择规格"
            class="accredit-select"
          >
            <el-option
              v-for="item in unitList"
              :key="item.unit"
              :label="item.unit"
              :value="item.unit"
            >
            </el-option>
          </el-select>
        </template>
        <template v-slot:materialNum>
          <el-input-number v-model="formDataDialog.materialNum"
                    :min="0" @change="materialNumChange"
                    placeholder='请输入订货数量'>
          </el-input-number>
        </template>
        <template v-slot:materialPackNum>
          <el-input-number v-model="formDataDialog.materialPackNum"
                    :min="0" :disabled="true"
                    placeholder='请输入订货数量'>
          </el-input-number>
        </template>
        <template v-slot:supplierId>
          <el-select
            v-model="formDataDialog.supplierId"
            filterable
            :disabled="formDataDialog.materialType === '辅料'"
            style="width:100%"
            placeholder="请选择供应商"
            class="accredit-select"
          >
            <el-option
              v-for="item in supList"
              :key="item.vendorCode"
              :label="item.vendorName"
              :value="item.vendorCode"
            >
            </el-option>
          </el-select>
        </template>
      </ele-form-drawer>
      <ele-dialog-table
        title="物料查询"
        width="800px"
        :visible.sync="mixinDialogVisibleJc"
        :formConfig="mixinSearchDialogJc"
        :column="mixinDialogColumn"
        @getSelectData="getSelectMixin"
        :getList="getMixinListJc"
        :hasFooter="hasMixinFooter"
      ></ele-dialog-table>
      <ele-dialog-table
        title="物料查询"
        width="800px"
        :visible.sync="mixinDialogVisible"
        :formConfig="mixinSearchDialog"
        :column="mixinDialogColumn"
        @getSelectData="getSelectMixinSpIn"
        :getList="getMixinList"
        :hasFooter="hasMixinFooter"
      ></ele-dialog-table>
      <ele-form-drawer
        :isLoading="isLoading"
        v-model="formDataDialogSpIn"
        v-bind="formDescDialogSpIn"
        :request-fn="handleSubmitSpIn"
        :visible.sync="spInVisible"
        :title="title"
      >
        <template v-slot:materialName>
          <el-input v-model="formDataDialogSpIn.materialName"
                    readonly
                    placeholder='请选择物料'>
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="mixinDialogVisible = true"></el-button>
          </el-input>
        </template>
        <template v-slot:itdPackType>
          <el-select
            v-model="formDataDialogSpIn.itdPackType"
            filterable
            style="width:100%"
            placeholder="请选择入库方式"
            class="accredit-select"
            @change="itdPackTypeChangeSpIn(formDataDialogSpIn.itdPackType)"
          >
            <el-option
              v-for="item in itdPackTypeList"
              :key="item.id"
              :label="item.val"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </template>
        <template v-slot:materialBrand>
          <el-select
            v-model="formDataDialogSpIn.materialBrand"
            filterable
            style="width:100%"
            placeholder="请选择品牌"
            class="accredit-select"
            @change="getMaterialUnitSpIn(formDataDialogSpIn)"
          >
            <el-option
              v-for="item in brandList"
              :key="item"
              :label="item"
              :value="item"
            >
            </el-option>
          </el-select>
        </template>
        <template v-slot:materialUnit>
          <el-select
            v-model="formDataDialogSpIn.materialUnit"
            filterable
            @change="materialUnitChangeSpIn"
            style="width:100%"
            placeholder="请选择规格"
            class="accredit-select"
          >
            <el-option
              v-for="item in unitList"
              :key="item.unit"
              :label="item.unit"
              :value="item.unit"
            >
            </el-option>
          </el-select>
        </template>
        <template v-slot:materialNum>
          <el-input-number v-model="formDataDialogSpIn.materialNum"
                           :min="0" @change="materialNumChangeSpIn"
                           placeholder='请输入订货数量'>
          </el-input-number>
        </template>
        <template v-slot:materialPackNum>
          <el-input-number v-model="formDataDialogSpIn.materialPackNum"
                           :min="0" :disabled="true"
                           placeholder='请输入订货数量'>
          </el-input-number>
        </template>
        <template v-slot:supplierId>
          <el-select
            v-model="formDataDialogSpIn.supplierId"
            filterable
            :disabled="formDataDialogSpIn.materialType === '辅料'"
            style="width:100%"
            placeholder="请选择供应商"
            class="accredit-select"
          >
            <el-option
              v-for="item in supList"
              :key="item.vendorCode"
              :label="item.vendorName"
              :value="item.vendorCode"
            >
            </el-option>
          </el-select>
        </template>
      </ele-form-drawer>
      <ele-form-drawer
        :isLoading="isLoading"
        v-model="formDataDialogSpOut"
        v-bind="formDescDialogSpOut"
        :request-fn="handleSubmitSpOut"
        :visible.sync="spOutVisible"
        :title="title"
      >
        <template v-slot:outUnit>
          <el-select
            style="width:100%"
            v-model="formDataDialogSpOut.outUnit"
            placeholder="请选择出库单位"
            class="accredit-select"
            @change="outUnitChange"
          >
            <el-option
              v-for="item in formDataDialogSpOut.outUnitList"
              :key="item.val"
              :label="item.val"
              :value="item.val"
            >
            </el-option>
          </el-select>
        </template>
        <template v-slot:materialNum>
          <el-input-number v-model="formDataDialogSpOut.materialNum"
                           :min="0" @change="materialNumChangeSpOut"
                           placeholder='请输入出库数量'>
          </el-input-number>
        </template>
        <template v-slot:materialPackNum>
          <el-input-number v-model="formDataDialogSpOut.materialPackNum"
                           :min="0" :disabled="true"
                           placeholder='请输入出库数量'>
          </el-input-number>
        </template>
      </ele-form-drawer>
    </div>
  </div>
</template>

<script>
import eleFormSearch from "@/components/ele-form-search/index";
import {operateList, searchConfig, formDescDialog,formDescDialogSpOut, formDescDialogSpIn,formConfig} from './config'

import {mixinDialog} from '@/views/materials/tmMaterialList/ele-dialog-table/mixin'
import {repairItemCreate, repairItemDeleteById, repairItemPage, repairItemUpdate} from "@/api/repair/item";
import {getDict} from "@/api/common";
import dialogRepairTable from '@/views/materials/tmMaterialList/ele-dialog-table/index'
import {mesKtStockInfoPage, mesKtStockInfoDetailPage} from "@/api/mesKtStockInfo/mesKtStockInfo";
import {getCurrentWarehouseCode, inStockSpecial} from "@/api/inbound/mesInTask";
import {reinspectionPartCreate, reinspectionPartUpdate} from "@/api/reinspection/items";
import {mesTmMaterialBrands} from "@/api/materials/brand";
import {
  getUnitsDetailByBrand,
  getUnitsDetailByBrandII,
  mesTmMaterialUnits,
  mesTmMaterialUnitsDetail
} from "@/api/materials/unit";
import {createDemandByStock} from "@/api/materials/demand";
import {mesTmMaterialBaseSup} from "@/api/materials/tmMaterialBase";
import {outStockSpecial} from "@/api/outbound/wmsOutTask";
export default {
  name: 'repairItem',
  components: {dialogRepairTable, eleFormSearch},
  mixins: [searchConfig, mixinDialog],
  props: {
    // 是否要分页
    pagination: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    const self = this
    return {
      selfMaxHeight: 0, // 最大高度
      formData:{},
      tableData:[],
      currentPage:1,
      total:0,
      pageSize:10,
      demandPackUnit:'',
      demandPackCapacity:1,
      title: null,
      visible: false,
      spInVisible: false,
      spOutVisible: false,
      isLoading: false,
      loading: false,
      subRequestParams: {
        column: [{key: 'itemCode', value: 'itemCode'}]
      },
    //  detailVisible:false,
      otherParam:{},
      formDataDialog: {},
      formDataDialogSpIn: {},
      formDataDialogSpOut: {},
      operateList,
      mesKtStockInfoPage, mesKtStockInfoDetailPage, formDescDialog,formDescDialogSpOut,formDescDialogSpIn,
      // 列表页字段的绑定配置
      formConfig, //搜索配置
      brandList:[],
      itdPackTypeList:[
        {
          id:'1',val:'基础单位入库'
        },
        {
          id:'2',val:'采购单位入库'
        }
      ],
      unitList:[],
      itdPackType:'',
      supList:[],
      column: [
        // {
        //   type: 'selection',
        //   fixed: 'left'
        // },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          width: 60,
          fixed: 'left'
        },
        // {
        //   type: 'expand',
        //   width: 60,
        // },
        {
          prop: 'itemName',
          label: '物料名称',
          showOverflowTooltip: true
        },
        {
          prop: 'itemCode',
          label: '物料编号',
          showOverflowTooltip: true
        },
        {
          prop: 'itemNum',
          label: '数量',
          showOverflowTooltip: true
        },
      ],
      columnDetail: [
        {
          type: 'selection',
          fixed: 'left'
        },
        {
          type: 'index',
          label: $i18n.t('common.order'),
          width: 60,
          fixed: 'left'
        },
        {
          prop: "warehouseCode",
          columnKey: "warehouseName",
          label: $i18n.t("common.warehouseName"),
          fixed: "left",
          width: 150,
          optionProp: {
            value: "modelingCode",
            label: "modelingName",
          },
          option: async (data) => {
            const res = await getCurrentWarehouseCode();
            let list = res.data.result || []
            list.forEach(val => {
              val.modelingName = `${val.modelingCode}-${val.modelingName}`
            });
            return list;
          },
        },
        {
          prop: 'itemName',
          label: '物料名',
          showOverflowTooltip: true
        },
        {
          prop: 'itemBrand',
          label: '品牌',
          showOverflowTooltip: true
        },
        {
          prop: 'itemUnit',
          label: '规格',
          showOverflowTooltip: true
        },
        {
          prop: 'itemNum',
          label: '数量',
          showOverflowTooltip: true
        },
        {
          prop: 'itemVin',
          label: 'VIN关联',
          showOverflowTooltip: true
        },
        {
          prop: 'itemQuality',
          label: '品质',
          showOverflowTooltip: true
        },
        {
          prop: 'itemSup',
          label: '供应商',
          showOverflowTooltip: true
        },
        // {
        //   prop: 'operate',
        //   label: $i18n.t('common.operation'),
        //   width: 160,
        //   fixed: 'right',
        //   render: (h, scope) => {
        //     return <ele-row-operation scope={scope} rowConfig={rowConfig} onRowOperate={this.rowOperate} />
        //   }
        // }
      ],
      warHouseDict:[]
    }
  },
  computed: {},
  created() {
    this.getWarHouseDict()

  },
  mounted() {
    this.handleSearch()
  },
  methods: {
    tableRowClassName({row, rowIndex}) {
      if (row.materialSafetyStock && row.materialSafetyStock > row.itemNum) {
        return 'warning-row';
      }
      return '';
    },
    handleSearchPageOne(){
      this.currentPage=1
      this.handleSearch()
    },
    handleSearch(){
      let params={
        ...this.$refs.eleFormSearch.formData,
        pageSize:this.pageSize,
        pageNum:this.currentPage
      }
      mesKtStockInfoPage(params).then((res)=>{
        this.tableData=res.data.result.records
        this.total=Number(res.data.result.total)
      })
    },
    handleReset(){
      this.currentPage=1
      this.pageSize=10
      this.formData={}
      this.handleSearch()
    },
    handleSizeChange(val){
      this.pageSize=val
      this.handleSearch()
    },
    handleCurrentChange(val){
      this.currentPage=val
      this.handleSearch()
    },
    formatter(row){
      const item = this.warHouseDict.find((i)=>{
       return i.modelingCode === row.warehouseCode
      })
      row.warehouseName = item.modelingName
      return item.modelingName
    },
    getWarHouseDict(){
      getCurrentWarehouseCode().then((res)=>{
        this.warHouseDict=res.data.result
      })
    },
    // rowClick(row) {
    //   this.detailVisible=true
    //   this.otherParam=row
    // },
    materialNumChange(val)
    {
      this.formDataDialog.materialPackNum = val * this.demandPackCapacity;
    },
    materialNumChangeSpOut(val)
    {
      this.formDataDialogSpOut.materialPackNum = val * this.demandPackCapacity;
    },
    materialNumChangeSpIn(val)
    {
      if(this.itdPackType === '2')
      {
        this.formDataDialogSpIn.materialPackNum = val * this.demandPackCapacity;
      }
      else
      {
        this.formDataDialogSpIn.materialPackNum = val;
      }

    },
    getMaterialUnit(row){
      this.$set(this.formDataDialog,'materialUnit',undefined)
      this.unitList = []
      this.demandPackCapacity = 1
      const params = {
        materialCode: row.materialCode,
        brand: row.materialBrand
      };
      getUnitsDetailByBrandII(params)
        .then((res) => {
          this.unitList  = res.data.result
        })
    },
    getMaterialUnitSpIn(row){
      this.$set(this.formDataDialogSpIn,'materialUnit',undefined)
      this.unitList = []
      this.demandPackCapacity = 1
      const params = {
        materialCode: row.materialCode,
        brand: row.materialBrand
      };
      getUnitsDetailByBrandII(params)
        .then((res) => {
          this.unitList  = res.data.result
        })
    },
    materialUnitChange(val)
    {
      this.unitList.forEach((p) => {
        if(p.unit === val)
        {
           this.demandPackCapacity= p.packCapacity
          this.demandPackUnit = p.packUnit
          this.materialNumChange(this.formDataDialog.materialNum)
        }
      })
    },
    itdPackTypeChangeSpIn(val)
    {
      this.itdPackType = val;
      this.materialNumChangeSpIn(this.formDataDialogSpIn.materialNum)
    },
    materialUnitChangeSpIn(val)
    {
      this.unitList.forEach((p) => {
        if(p.unit === val)
        {
          this.demandPackCapacity = p.packCapacity
          this.demandPackUnit = p.packUnit
          this.materialNumChangeSpIn(this.formDataDialogSpIn.materialNum)
        }
      })
    },
    outUnitChange(val)
    {
      console.warn(val)
      this.formDataDialogSpOut.outUnitList.forEach((p) => {
        if(p.val === val)
        {
          this.demandPackCapacity = p.cap
          this.demandPackUnit = p.val
          console.warn(this.demandPackUnit)
          this.materialNumChangeSpOut(this.formDataDialogSpOut.materialNum)
        }
      })
    },
    getSelectMixin(data) {
      // 筛选重复值,插入
      if (data[0].materialType !== '辅料' && data[0].materialType !== '集采') {
        this.$message.warning("非集采/辅料类物料不能直接创建需求单")
        this.formDataDialog = {}
        return
      }
      this.$set(this.formDataDialog, 'materialName', data[0].materialName)
      this.$set(this.formDataDialog, 'materialCode', data[0].materialCode)
      this.$set(this.formDataDialog, 'materialType', data[0].materialType)
      this.$set(this.formDataDialog, 'itemUnit', data[0].materialUnit)
      this.$set(this.formDataDialog, 'materialBrand', '')
      this.$set(this.formDataDialog, 'materialUnit', '')
      this.$set(this.formDataDialog, 'supplierId', '')
      this.unitList = []
      this.demandPackCapacity = 1

      if (data[0].materialType === '辅料') {
        this.formDescDialog.formDesc.materialPhotoUrl.required = true;
        this.formDescDialog.formDesc.supplierId.required = false;
        this.formDescDialog.formDesc.materialBrand.required = true;
        this.formDescDialog.formDesc.materialUnit.required = true;
      } else {
        this.formDescDialog.formDesc.materialPhotoUrl.required = false;
        this.formDescDialog.formDesc.supplierId.required = true;
        this.formDescDialog.formDesc.materialBrand.required = true;
        this.formDescDialog.formDesc.materialUnit.required = true;
      }

      this.isLoading = true
      mesTmMaterialBrands(data[0].materialCode)
        .then((res) => {
          this.brandList = res.data.result
        })

      // mesTmMaterialUnitsDetail(data[0].materialCode)
      //   .then((res) => {
      //     this.unitList = res.data.result
      //   })

      mesTmMaterialBaseSup(data[0].materialCode)
        .then((res) => {
          this.supList = res.data.result
        })

      if(this.supList.length === 1 && data[0].materialType === '集采')
      {
        this.$set(this.formDataDialog, 'supplierId',this.supList[0].vendorCode)
      }

      this.isLoading = false
    },
    getSelectMixinSpIn(data) {
      this.$set(this.formDataDialogSpIn, 'materialName', data[0].materialName)
      this.$set(this.formDataDialogSpIn, 'materialCode', data[0].materialCode)
      this.$set(this.formDataDialogSpIn, 'materialType', data[0].materialType)
      this.$set(this.formDataDialogSpIn, 'itemUnit', data[0].materialUnit)
      this.$set(this.formDataDialogSpIn, 'materialBrand', '')
      this.$set(this.formDataDialogSpIn, 'materialUnit', '')
      this.$set(this.formDataDialogSpIn, 'supplierId', '')
      this.unitList = []
      this.demandPackCapacity = 1

      if (data[0].materialType === '集采'){
        this.formDescDialogSpIn.formDesc.supplierId.required = true;
        this.formDescDialogSpIn.formDesc.materialBrand.required = true;
        this.formDescDialogSpIn.formDesc.materialUnit.required = true;
      }
      else if (data[0].materialType === '辅料') {
        this.formDescDialogSpIn.formDesc.supplierId.required = false;
        this.formDescDialogSpIn.formDesc.materialBrand.required = true;
        this.formDescDialogSpIn.formDesc.materialUnit.required = true;
      }
      else
      {
        this.formDescDialogSpIn.formDesc.supplierId.required = false;
        this.formDescDialogSpIn.formDesc.materialBrand.required = false;
        this.formDescDialogSpIn.formDesc.materialUnit.required = false;
      }

      this.isLoading = true
      mesTmMaterialBrands(data[0].materialCode)
        .then((res) => {
          this.brandList = res.data.result
        })

      // mesTmMaterialUnitsDetail(data[0].materialCode)
      //   .then((res) => {
      //     this.unitList = res.data.result
      //   })

      mesTmMaterialBaseSup(data[0].materialCode)
        .then((res) => {
          this.supList = res.data.result
        })

      if(this.supList.length === 1 && data[0].materialType === '集采')
      {
        this.$set(this.formDataDialogSpIn, 'supplierId',this.supList[0].vendorCode)
      }

      this.isLoading = false
    },
    handleSubmit(data) {
      if (this.formDataDialog.materialNum <= 0) {
        this.$message.warning("请输入大于0的数量")
        return
      }
      if (data.materialType === '辅料') {
        if( !data.materialPhotoUrl)
        {
          this.$message.warning("辅料必须上传图片")
          return
        }
        if(this.supList.length === 0)
        {
          this.$message.warning("当前辅料没有供应商，请在供应商管理页面配置供货列表")
          return
        }
      }
      if (data.materialPhotoUrl) {
        data.materialPhotoUrl = data.materialPhotoUrl.map((r) => r.src).join(',')
      }
      this.isLoading = true
      const newData =
        {
          ...data,
          demandPackUnit:this.demandPackUnit,
          demandPackCapacity:this.demandPackCapacity
        }
      createDemandByStock(newData)
        .then((res) => {
          const message = res.data.message;
          this.$message.success(message || "操作完成");
          this.visible = false;
          this.refresh();
        })
        .finally(() => {
            this.isLoading = false
          }
        )

    },
    handleSubmitSpIn(data) {
      if (this.formDataDialogSpOut.materialNum <= 0) {
        this.$message.warning("请输入大于0的数量")
        return
      }

      console.warn(data)
      this.isLoading = true
      const newData =
        {
          itdPackType:data.itdPackType,
          goodsCode:data.materialCode,
          unit:data.materialUnit,
          brand:data.materialBrand,

          planAmount:data.materialNum,
          goodsName:data.materialName,
          //supplierId:data.materialType,
          supplierId:data.supplierId,
        }
      inStockSpecial(newData)
        .then((res) => {
          const message = res.data.message;
          this.$message.success(message || "入库单创建成功");
          this.spInVisible = false;
          this.refresh();
        })
        .finally(() => {
            this.isLoading = false
          }
        )
    },
    handleSubmitSpOut(data) {
      if (this.formDataDialogSpOut.materialNum <= 0) {
        this.$message.warning("请输入大于0的数量")
        return
      }
      this.isLoading = true
      const newData =
        {
          outCountType:data.outUnit,
          goodsCode:data.itemCode,
          goodsName:data.itemName,
          unit:data.itemUnit,
          brand:data.itemBrand,
          outAmount:data.materialNum,
          otPackCapacity:data.packCapacity,
          supplierId:data.itemSup,
          supplierName:data.itemSupName,
        }
      outStockSpecial(newData)
        .then((res) => {
          const message = res.data.message;
          this.$message.success(message || "出库单创建成功");
          this.spOutVisible = false;
          this.refresh();
        })
        .finally(() => {
            this.isLoading = false
          }
        )
    },
    handleOutSpecial(val)
    {
      let outUnitList =
        val.itemPackUnit &&　val.itemPackUnit !== '无' ?
          [{val:val.materialUnit,cap:1},{val:val.itemPackUnit,cap:val.packCapacity}] :
          [{val:val.materialUnit,cap:1}]
      this.formDataDialogSpOut = {
        ...val,
        outUnitList:outUnitList,
        materialPackNum:0
      }
      console.info(this.formDataDialogSpOut)
      this.spOutVisible = true
    },
    // 表格顶部按钮操作事件
    spIn(){
      this.formDataDialogSpIn = {}
      this.spInVisible = true
    },
    add(){
      this.formDataDialog = {}
      this.visible = true
    },
    show(){
      this.formDataDialog = {}
      this.visible = true
    },
    handleOperateEvent(data) {
      this.title = data.name
      const fnc = {
        add: () => {
          this.formDataDialog = {}
          this.visible = true
        },
      }
      fnc[data.handleName]()
    },
    // 表格行操作事件
    rowOperate({handleName, name, row}) {
      this.title = name
      const fnc = {
        // edit: () => {
        //   this.formDataDialog = { ...row }
        //   this.visible = true
        // },
        // delete: () => {
        //   this.$confirm('此操作将删除所选数据及关联明细数据, 是否继续?', $i18n.t('common.tip'), {
        //     confirmButtonText: $i18n.t('common.ok'),
        //     cancelButtonText: $i18n.t('common.cancel'),
        //     type: 'warning'
        //   }).then(() => {
        //     this.rowDel(row.id)
        //   })
        // }
      }
      fnc[handleName]()
    },
    // 刷新表格数据
    refresh(isReset = true) {
      this.$refs.table.refresh(isReset)
    }
  }
}
</script>
<style>
.el-table .warning-row {
  background: #FF00007F;
}

.el-table .success-row {
  background: #c8ffc8;
}
</style>
